<template lang="">

  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px ;width: 100%;"
  >
    <el-col :span="20">
      <!--  -->
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodeData.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>

</template>
<script>
// 按需导入
import { reqDelDepartment } from '@/api/departments.js'
export default {
  name: 'TreeTools',
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    // 是否根节点
    isRoot: {
      type: Boolean,
      default: false
    }

  },
  // created() {
  //   console.log(this.nodeData)
  // },
  methods: {
    async  handleCommand(type) {
      if (type === 'add') {
        // 添加
        console.log('add')
        this.$emit('add-deots', this.nodeData)
      }
      if (type === 'edit') {
        // 编辑
        this.$emit('edit-deots', this.nodeData)
      }
      // 删除
      if (type === 'del') {
        const res = await this.$confirm('你确认要进行删除么?').catch(err => err)
        if (res !== 'confirm') return
        console.log('del')
        // console.log(this.nodeData.id)
        // 删除有问题
        const res1 = await reqDelDepartment(this.nodeData.id)// 传值  删除  需要 id
        console.log(res1)
        console.log(this.nodeData.id)

        this.$message.success('删除成功')
        this.$emit('del-depts') // 通知父组件  刷新数据
      }
    }
  }

}
</script>

<style scoped>
.tree-card {
  padding: 30px 30px;
  font-size:14px;
}
</style>
